------------------------------------------------------------
          HVCI Driver Compatibility 
------------------------------------------------------------

There are some restrictions protecting device drivers with HVCI driver compatibility. The following steps will allow you to create a protected, HVCI-compatible device driver.

1. Protect Using Stealth Mode Insertion:

   In your source code, you need to add a "Stealth Regs Area" and a "Stealth Code Area". You can use the following code snippet to create these areas:

   ------------------------------------------------------------
   #include <VirtualizerSDK.h>

   // *****************************************************************************
   // Here, please, increase the number of chunks for data and code
   // You might need to increase this value if you add more VMs or 
   // add complex VMs
   // *****************************************************************************
   #define NUMBER_OF_DATA_CHUNKS 2
   #define NUMBER_OF_CODE_CHUNKS 4

   #ifdef ARM64
      // Force the objects to be linked in.
      #pragma comment(linker, "/INCLUDE:StealthDataArea")
      #pragma comment(linker, "/INCLUDE:StealthCodeArea")
   #endif

   // Create space for VM data and VM code in the .text and .data sections
   #define _1KB (1024)
   #define _32KB (_1KB * 32)
   #define _512KB (_1KB * 512)

   #define STEALTH_DATA_CHUNK _32KB
   #define STEALTH_CODE_CHUNK _512KB

   template <size_t Size>
   struct STEALTH_AREA {
      unsigned int Start[4];
      char Buffer[Size];
      unsigned int End[4];
   };

   // Data storage for VMs.
   extern "C"
   {
      // Data storage for VMs.
      #pragma data_seg(".data")
      __declspec(allocate(".data"))
               STEALTH_AREA<STEALTH_DATA_CHUNK * NUMBER_OF_DATA_CHUNKS> StealthDataArea =
      {
               { 0xA5A6A7A8, 0xA8A7A6A5, 0xB5A5B6A6, 0xB7A7A5A5 },
               { 0 },
               { 0xB8B7B6B5, 0xA6B6C6D6, 0xA7A6A4A4, 0xA4A5B1B2 }
      };

      // Code storage for VMs.
      #pragma code_seg(".text")
      __declspec(allocate(".text"))
               STEALTH_AREA<STEALTH_CODE_CHUNK * NUMBER_OF_CODE_CHUNKS> StealthCodeArea =
      {
               { 0xA1A2A3A4, 0xA4A3A2A1, 0xB1A1B2A2, 0xB8A8A1A1 },
               { 0 },
               { 0xB6B5B3B6, 0xA2B2C2D2, 0xA9A8A2A2, 0xA0A9B9B8 }
      };
   }

   ------------------------------------------------------------

2. Configure Advanced Options:

   Go to the Advanced Options panel and add the following options:

   - OPTION_PROTECTION_PRESERVE_SECTIONS_FLAGS=YES
   - OPTION_ADVANCED_HARDWARE_STACK_PROTECTION_COMPATIBLE=YES

3. Set Protection Options:

   In the "Protection Options" panel, select "Stealth Mode" in the option "Location of protection code".

4. String Virtualization, MUTATE Macros:

   String Virtualization and MUTATE macros are *not* allowed in versions < 3.2.0

   In versions >= 3.2.0 you can use String Encryption

5. Disable Optimizations Locally:

   It’s better to disable optimizations locally (using #pragma) and ensure "no inline" in all functions where you use VIRTUALIZER_XXXXX_START/END markers. Example:

   ------------------------------------------------------------
   #pragma optimize( "", off)
   __declspec(noinline) void MyFunction()
   {
       VIRTUALIZER_START
       // your code
       VIRTUALIZER_END
   }
   #pragma optimize( "", on)
   ------------------------------------------------------------

6. Optional MAP File Markers:

   Instead of using the VIRTUALIZER_XXXXX markers (as in the above example), you can add them via a MAP file. This is optional but recommended by some developers that protect device drivers.

7.  Protect Your Device Driver

